var t = require("../../../@babel/runtime/helpers/toConsumableArray"), a = require("../../../@babel/runtime/helpers/defineProperty"), e = getApp();

Page({
    data: {
        page: 1,
        last_page: 1,
        micro_communities: [],
        commentPage: 1,
        comment_last_page: 1,
        noMoreComment: !1,
        third_content: [],
        istype: "comment"
    },
    onLoad: function(t) {
        t.gid && this.setData({
            goodsId: t.gid
        }), t.istype && this.setData({
            istype: t.istype
        }), t.comment_name && this.setData({
            comment_name: t.comment_name
        }), "comment" == this.data.istype ? (wx.setNavigationBarTitle({
            title: t.comment_name ? t.comment_name : "全部评价"
        }), this.getCommentData()) : (wx.setNavigationBarTitle({
            title: "更多微贴"
        }), this.getMic());
    },
    goMicro: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageC/micro_communities/microCommentDetails/microCommentDetails?stickId=" + a
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onReachBottom: function() {
        "comment" == this.data.istype ? this.getMoreComment() : this.getMoreMic();
    },
    onShareTimeline: function() {
        var t = {
            title: "".concat(this.data.comment_name ? this.data.comment_name : "全部评价"),
            query: "/packageA/others/GoodsComment/GoodsComment?"
        };
        return this.data.goodsId && (t.query += "gid=".concat(this.data.goodsId)), this.data.istype && (t.query += "&istype=".concat(this.data.istype)), 
        this.data.comment_name && (t.query += "&comment_name=".concat(this.data.comment_name)), 
        t;
    },
    onShareAppMessage: function() {
        var t = {
            title: "".concat(this.data.comment_name ? this.data.comment_name : "全部评价"),
            path: "/packageA/others/GoodsComment/GoodsComment?"
        };
        return this.data.goodsId && (t.path += "gid=".concat(this.data.goodsId)), this.data.istype && (t.path += "&istype=".concat(this.data.istype)), 
        this.data.comment_name && (t.path += "&comment_name=".concat(this.data.comment_name)), 
        t;
    },
    getMoreMic: function() {
        if (this.data.page >= this.data.last_page) console.log("没有更多"); else {
            wx.showLoading({
                title: "加载中"
            }), this.setData({
                page: this.data.page + 1
            });
            var t = this, o = e.getNetAddresss("plugin.micro-communities.api.goods.index");
            e._getNetWork({
                url: o,
                data: {
                    page: this.data.page,
                    goods_id: this.data.goods_info.get_goods.id
                },
                success: function(e) {
                    var o, n = e.data;
                    1 == n.result && t.setData((a(o = {}, "micro_communities.list", t.data.micro_communities.list.concat(n.data.data)), 
                    a(o, "last_page", n.data.last_page), o));
                    wx.hideLoading();
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    getMic: function() {
        this.setData({
            page: 1
        });
        var t = this, o = e.getNetAddresss("plugin.micro-communities.api.goods.index");
        e._getNetWork({
            url: o,
            data: {
                page: this.data.page,
                goods_id: this.data.goodsId
            },
            success: function(e) {
                var o, n = e.data;
                1 == n.result && t.setData((a(o = {}, "micro_communities.list", n.data.data), a(o, "last_page", n.data.last_page), 
                o));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getMoreComment: function() {
        if (this.data.commentPage >= this.data.comment_last_page) console.log("没有更多了"); else {
            var a = this;
            this.data.commentPage = this.data.commentPage + 1;
            var o = e.getNetAddresss("goods.comment.get-comment");
            o += "&goods_id=" + this.data.goodsId, o += "&page=" + this.data.commentPage, e._getNetWork({
                showToastIn: !1,
                url: o,
                success: function(e) {
                    var o = e.data;
                    1 == o.result && a.setData({
                        third_content: [].concat(t(a.data.third_content), t(o.data.data)),
                        streetShow: !0
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    getCommentData: function() {
        var a = this, o = e.getNetAddresss("goods.comment.get-comment");
        o += "&goods_id=" + this.data.goodsId, o += "&page=" + this.data.commentPage, e._getNetWork({
            showToastIn: !1,
            url: o,
            success: function(o) {
                var n = o.data;
                1 == n.result ? (n.data.data.length < 20 && a.setData({
                    noMoreComment: !0
                }), a.setData({
                    commentPage: 1,
                    comment_last_page: n.data.last_page
                }), a.data.third_content || a.setData({
                    third_content: []
                }), a.setData({
                    third_content: [].concat(t(a.data.third_content), t(n.data.data)),
                    streetShow: !0
                }), e._isTextEmpty(a.data.third_content) ? a.setData({
                    thirKong: !1
                }) : a.setData({
                    thirKong: !0
                })) : a.setData({
                    is_third_content: !1
                });
            },
            fail: function(t) {
                a.setData({
                    is_third_content: !1
                });
            }
        });
    },
    previewImage: function(t) {
        var a = t.currentTarget.dataset, e = a.images, o = a.src;
        wx.previewImage({
            current: o,
            urls: e
        });
    },
    toContentInfo: function(t) {
        var a = t.currentTarget.dataset.jsondata, e = "/packageD/member/CommentDetails/CommentDetails";
        e = "".concat(e, "?order_id=").concat(a.order_id, "&goods_id=").concat(a.goods_id, "&comment_id=").concat(a.id, "&order_goods_id=").concat(a.order_goods_id, "&uid=").concat(a.uid), 
        wx.navigateTo({
            url: e
        });
    }
});